#include "ChooseFile.h"
#include<QtDebug>
ChooseFile::ChooseFile(QWidget* parent):QDialog(parent)
{
	ui.setupUi(this);
	connect(ui.inputFile,SIGNAL(editTextChanged(const QString&)),this,SLOT(GetText(const QString&)));
	connect(ui.fileList,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(GetItemText(QListWidgetItem*)));
	FileTree = NULL;
	ui.fileList->clear();
}

ChooseFile::~ChooseFile(void)
{
	FileTree = NULL;
}

void ChooseFile::GetTree(tree* tree)
{
	FileTree = tree;
}

void ChooseFile::GetItemText(QListWidgetItem* item)
{
	emit LoadCode(item->text());
}

void ChooseFile::GetText(const QString& text)
{
	if(FileTree!= NULL)
	{
		if(text.isEmpty() || text.isNull())
		{
			FileTree->show_all(ui.fileList);	
		}
		else
		{
			FileTree->find(text,ui.fileList);	
		}
	}
}

void ChooseFile::exec()
{
	FileTree->show_all(ui.fileList);
	QDialog::exec();
}
